home *** CD-ROM | disk | FTP | other *** search
- #include "DemoRoutines.h"
-
- OSErr TestGetSetPixel(PicHandle pict)
- {
- GDHandle oldGD;
- GWorldPtr oldGW;
- GWorldPtr myOffGWorld;
- PixMapHandle myPixMapHandle;
-
- short x,y;
- Rect bounds;
- Rect mybounds;
- PixMap *myPixMapPtr;
- long startTicks;
- Str255 theString;
- RGBColor myRGB;
-
- bounds = (*pict)->picFrame;
- mybounds = bounds;
- OffsetRect( &mybounds, -mybounds.left, -mybounds.top);
- DrawPicture( pict, &mybounds );
- OffsetRect( &bounds, 100, 100 );
-
- if( !NewGWorld( &myOffGWorld, 32, &bounds, 0, 0, 0 ) )
- {
- GetGWorld(&oldGW,&oldGD);
- SetGWorld(myOffGWorld,nil);
-
- EraseRect( &bounds ); /* clear the GWorld */
-
- myPixMapHandle = GetGWorldPixMap( myOffGWorld ); /* 7.0 only */
-
- LockPixels( myPixMapHandle );
- DrawPicture( pict, &bounds );
-
- myPixMapHandle = GetGWorldPixMap( myOffGWorld );
-
- startTicks = *(long*)0x16a;
- for( y = bounds.top; y< bounds.bottom; y++ )
- {
- for( x = bounds.left; x < bounds.right; x++ )
- {
- GetCPixel( x, y, &myRGB );
- myRGB.red ^=0xFFFF; /* invert the red and green channels */
- myRGB.green ^=0xFFFF;
- SetCPixel( x, y, &myRGB );
- }
- }
-
- SetGWorld(oldGW,oldGD);
-
- TextMode( srcCopy );
- MoveTo( 30,30 );
- { long ticks = *(long*)0x16a - startTicks;
- NumToString( ticks, theString ); /* Ticks */
- DrawString( theString );
- }
- myPixMapHandle = GetGWorldPixMap( myOffGWorld ); /* 7.0 only */
- CopyBits( (BitMap*)*myPixMapHandle, (BitMap*)&thePort->portBits, &bounds, &bounds, srcCopy, 0 );
- DisposeGWorld( myOffGWorld );
- }
- else
- return memFullErr;
- return noErr;
- }
-
- OSErr TestBetterGetSetPixel(PicHandle pict)
- {
- GDHandle oldGD;
- GWorldPtr oldGW;
- GWorldPtr myOffGWorld;
- PixMapHandle myPixMapHandle;
-
- short x,y;
- long myPixel;
- Rect bounds;
- Rect mybounds;
- long startTicks;
- Str255 theString;
-
- bounds = (*pict)->picFrame;
- mybounds = bounds;
- OffsetRect( &mybounds, -mybounds.left, -mybounds.top);
- DrawPicture( pict, &mybounds );
- OffsetRect( &bounds, 100, 100 );
-
- if( !NewGWorld( &myOffGWorld, 32, &bounds, 0, 0, 0 ) )
- {
- GetGWorld(&oldGW,&oldGD);
- SetGWorld(myOffGWorld,nil);
-
- EraseRect( &bounds ); /* clear the GWorld */
-
- myPixMapHandle = GetGWorldPixMap( myOffGWorld ); /* 7.0 only */
-
- LockPixels( myPixMapHandle );
- DrawPicture( pict, &bounds );
- UnlockPixels( myPixMapHandle );
-
- startTicks = *(long*)0x16a;
- LockPixels( myPixMapHandle );
- for( y = bounds.top; y< bounds.bottom; y++ )
- {
- for( x = bounds.left; x < bounds.right; x++ )
- {
- myPixel = GWGet32PixelC( myOffGWorld, x, y );
- myPixel ^= 0x00FFFF00; /* invert the red and green channels */
- GWSet32PixelC( myOffGWorld, x, y, myPixel );
- }
- }
-
- SetGWorld(oldGW,oldGD);
-
- TextMode( srcCopy );
- MoveTo( 30,30 );
- { long ticks = *(long*)0x16a - startTicks;
- NumToString( ticks, theString ); /* Ticks */
- DrawString( theString );
- }
-
- myPixMapHandle = GetGWorldPixMap( myOffGWorld ); /* 7.0 only */
- CopyBits( (BitMap*)*myPixMapHandle, (BitMap*)&thePort->portBits, &bounds, &bounds, srcCopy, 0 );
- DisposeGWorld( myOffGWorld );
- }
- else
- return memFullErr;
- return noErr;
- }
-
-
-
- OSErr
- TestFastGetSetPixel(PicHandle pict)
- {
- GDHandle oldGD;
- GWorldPtr oldGW;
- GWorldPtr myOffGWorld;
- PixMapHandle myPixMapHandle;
-
- short x,y;
- long myPixel;
- Rect bounds;
- Rect mybounds;
- long *srcBaseAddr;
- char mmuMode;
- PixMap *myPixMapPtr;
- long startTicks;
- Str255 theString;
-
- bounds = (*pict)->picFrame;
- mybounds = bounds;
- OffsetRect( &mybounds, -mybounds.left, -mybounds.top);
- DrawPicture( pict, &mybounds );
- OffsetRect( &bounds, 100, 100 );
-
- if( !NewGWorld( &myOffGWorld, 32, &bounds, 0, 0, 0 ) )
- {
- GetGWorld(&oldGW,&oldGD);
- SetGWorld(myOffGWorld,nil);
-
- EraseRect( &bounds ); /* clear the GWorld */
-
- myPixMapHandle = GetGWorldPixMap( myOffGWorld ); /* 7.0 only */
-
- LockPixels( myPixMapHandle );
- DrawPicture( pict, &bounds );
- UnlockPixels( myPixMapHandle );
-
- srcBaseAddr = (long *) GetPixBaseAddr ( myPixMapHandle ); /* get 32-bit base address of the pixmap */
- myPixMapPtr = *myPixMapHandle;
-
- /*
- ** WARNING: The PixMapHandle is dereferenced throughout these next loops.
- ** The code makes sure memory will not move. In particular, it is important that
- ** the segment containing the FastGWGet32Pixel and FastGWSet32Pixel routines
- ** is already loaded, or is in the same segment as the caller. Otherwise memory might
- ** move when the segment is loaded. A trick to make sure the segment is loaded is to call
- ** a routine in the same segment (or these routines themselves) before making assumptions
- ** about memory not moving.
- */
- /* Make it 32-bit clean */
- LockPixels(myPixMapHandle);
- myPixMapPtr = (PixMap *)StripAddress( (Ptr)myPixMapPtr ); /* Make it 32-bit clean */
-
- mmuMode = true32b;
- SwapMMUMode ( &mmuMode ); /* set the MMU to 32-bit mode */
- startTicks = *(long*)0x16a;
- for( y = bounds.top; y< bounds.bottom; y++ )
- {
- for( x = bounds.left; x < bounds.right; x++ )
- {
- myPixel = FastGWGet32Pixel( myPixMapPtr, srcBaseAddr, x, y );
- myPixel ^= 0x00FFFF00; /* invert the red and green channels */
- FastGWSet32Pixel( myPixMapPtr, srcBaseAddr, x, y, myPixel );
- }
- }
- SwapMMUMode ( &mmuMode ); /* set it back */
-
- SetGWorld(oldGW,oldGD);
-
- TextMode( srcCopy );
- MoveTo( 30,30 );
- NumToString( *(long*)0x16a - startTicks, theString ); /* Ticks */
- DrawString( theString );
-
- myPixMapHandle = GetGWorldPixMap( myOffGWorld ); /* 7.0 only */
- CopyBits( (BitMap*)*myPixMapHandle, (BitMap*)&thePort->portBits, &bounds, &bounds, srcCopy, 0 );
- DisposeGWorld( myOffGWorld );
- }
- else
- return memFullErr;
- return noErr;
- }
-
-
- OSErr
- TestRedGreenInvert(PicHandle pict)
- {
- GDHandle oldGD;
- GWorldPtr oldGW;
- GWorldPtr myOffGWorld;
- PixMapHandle myPixMapHandle;
-
- short x,y;
- long myPixel;
- Rect bounds;
- Rect mybounds;
- long srcBaseAddr;
- PixMap *myPixMapPtr;
- long startTicks;
- Str255 theString;
-
- bounds = (*pict)->picFrame;
- mybounds = bounds;
- OffsetRect( &mybounds, -mybounds.left, -mybounds.top);
- DrawPicture( pict, &mybounds );
- OffsetRect( &bounds, 100, 100 );
-
- if( !NewGWorld( &myOffGWorld, 32, &bounds, 0, 0, 0 ) )
- {
- GetGWorld(&oldGW,&oldGD);
- SetGWorld(myOffGWorld,nil);
-
- EraseRect( &bounds ); /* clear the GWorld */
-
- myPixMapHandle = GetGWorldPixMap( myOffGWorld ); /* 7.0 only */
-
- LockPixels( myPixMapHandle );
- DrawPicture( pict, &bounds );
- UnlockPixels( myPixMapHandle );
-
-
- startTicks = *(long*)0x16a;
-
- RedGreenInvert( myOffGWorld );
-
- SetGWorld(oldGW,oldGD);
- TextMode( srcCopy );
- MoveTo( 30,30 );
- NumToString( *(long*)0x16a - startTicks, theString ); /* Ticks */
- DrawString( theString );
- CopyBits( (BitMap*)*myPixMapHandle, (BitMap*)&thePort->portBits, &bounds, &bounds, srcCopy, 0 );
- DisposeGWorld( myOffGWorld );
- }
- else
- return memFullErr;
- return noErr;
- }
-
- OSErr
- TestCalculateDelta(PicHandle pict)
- {
- OSErr err = memFullErr;
- GDHandle oldGD;
- GWorldPtr oldGW;
- GWorldPtr myOffGWorld;
- GWorldPtr myOffGWorld1;
- PixMapHandle myPixMapHandle;
- PixMapHandle myPixMapHandle1;
- CTabHandle myGrayCTable;
- Rect bounds, mybounds;
-
- bounds = (*pict)->picFrame;
- mybounds = bounds;
- OffsetRect( &mybounds, -mybounds.left, -mybounds.top);
- /* Draw it to the screen */
- DrawPicture( pict, &mybounds );
- OffsetRect( &bounds, 100, 100 );
-
- if( !NewGWorld( &myOffGWorld, 32, &bounds, 0, 0, 0 ) )
- {
- GetGWorld(&oldGW,&oldGD);
- SetGWorld(myOffGWorld,nil);
- EraseRect( &bounds ); /* clear the GWorld */
- myPixMapHandle = GetGWorldPixMap( myOffGWorld );
- LockPixels( myPixMapHandle );
- /* Draw it to the GWorld */
- DrawPicture( pict, &bounds );
- UnlockPixels( myPixMapHandle );
- SetGWorld(oldGW,oldGD); /* Copy to window */
- myGrayCTable = GetCTable( 40 ); /* Defaullt 256 gray table */
- if( !NewGWorld( &myOffGWorld1, 8, &bounds, myGrayCTable, 0, 0 ) )
- {
- CalculateDeltas( myOffGWorld, myOffGWorld1 );
- myPixMapHandle1 = GetGWorldPixMap( myOffGWorld1 ); /* 7.0 only */
- CopyBits( (BitMap *)*myPixMapHandle1, (BitMap *)&thePort->portBits, &bounds, &bounds, srcCopy, 0 );
- DisposeGWorld( myOffGWorld1 );
- err = noErr;
- }
- DisposeGWorld( myOffGWorld );
- }
-
- return err;
- }
-
- OSErr
- TestCalculateDeltaFast(PicHandle pict)
- {
- OSErr err = memFullErr;
- GDHandle oldGD;
- GWorldPtr oldGW;
- GWorldPtr myOffGWorld;
- GWorldPtr myOffGWorld1;
- PixMapHandle myPixMapHandle;
- PixMapHandle myPixMapHandle1;
- CTabHandle myGrayCTable;
- Rect bounds, mybounds;
-
- bounds = (*pict)->picFrame;
- mybounds = bounds;
- OffsetRect( &mybounds, -mybounds.left, -mybounds.top);
- /* Draw it to the screen */
- DrawPicture( pict, &mybounds );
- OffsetRect( &bounds, 100, 100 );
-
- if( !NewGWorld( &myOffGWorld, 32, &bounds, 0, 0, 0 ) )
- {
- GetGWorld(&oldGW,&oldGD);
- SetGWorld(myOffGWorld,nil);
- EraseRect( &bounds ); /* clear the GWorld */
- myPixMapHandle = GetGWorldPixMap( myOffGWorld );
- LockPixels( myPixMapHandle );
- /* Draw it to the GWorld */
- DrawPicture( pict, &bounds );
- UnlockPixels( myPixMapHandle );
- SetGWorld(oldGW,oldGD); /* Copy to window */
- myGrayCTable = GetCTable( 40 ); /* Defaullt 256 gray table */
- if( !NewGWorld( &myOffGWorld1, 8, &bounds, myGrayCTable, 0, 0 ) )
- {
- FastCalculateDeltas( myOffGWorld, myOffGWorld1 );
- myPixMapHandle1 = GetGWorldPixMap( myOffGWorld1 ); /* 7.0 only */
- CopyBits( (BitMap *)*myPixMapHandle1, (BitMap *)&thePort->portBits, &bounds, &bounds, srcCopy, 0 );
- DisposeGWorld( myOffGWorld1 );
- err = noErr;
- }
- DisposeGWorld( myOffGWorld );
- }
- }
-
-
- OSErr TestBoxScale(PicHandle pict)
- {
- GWorldPtr srcWorld;
- Rect srcBounds;
- Point srcCenter, screenCenter;
- short err;
-
- srcBounds = (*pict)->picFrame;
- OffsetRect( &srcBounds, -srcBounds.left, -srcBounds.top);
- /* Draw it to the screen */
- DrawPicture( pict, &srcBounds );
-
- srcWorld = PictToGWorld( pict, &srcBounds );
- if(srcWorld == nil)
- return memFullErr;
-
- srcBounds = srcWorld->portRect;
- SetPt(&srcCenter, srcBounds.right + srcBounds.left >> 1,
- srcBounds.bottom + srcBounds.top >> 1);
- SetPt(&screenCenter, thePort->portRect.right - thePort->portRect.left >> 1,
- thePort->portRect.bottom - thePort->portRect.top >> 1);
-
- {
- mapping map;
- GWorldPtr dstWorld, maskWorld;
- Rect dstBounds, screenBounds, maskBounds;
- PixMapHandle dstPixels, maskPixels;
-
- SetIdentityMapping(&map);
- ScaleMapping(&map, ff(1) + 0x8000, ff(1) + 0x8000, ff(srcCenter.h), ff(srcCenter.v));
-
- dstWorld = MapGWorldBox(srcWorld, &map, &maskWorld);
- dstPixels = GetGWorldPixMap( dstWorld );
- maskPixels = GetGWorldPixMap( maskWorld );
- dstBounds = dstWorld->portRect;
- maskBounds = maskWorld->portRect;
-
- screenBounds = dstBounds;
- CenterRect(&screenBounds, screenCenter.h, screenCenter.v);
-
- LockPixels(dstPixels);
- LockPixels(maskPixels);
- CopyDeepMask((BitMap*)*dstPixels, (BitMap*)*maskPixels, &thePort->portBits,
- &dstBounds, &maskBounds, &screenBounds, srcCopy + ditherCopy, 0);
- DisposeGWorld( maskWorld );
- DisposeGWorld( dstWorld );
- }
- DisposeGWorld( srcWorld );
- return noErr;
- }
-
- OSErr TestTentScale(PicHandle pict)
- {
- GWorldPtr srcWorld;
- Rect srcBounds;
- Point srcCenter, screenCenter;
- short err;
-
- srcBounds = (*pict)->picFrame;
- OffsetRect( &srcBounds, -srcBounds.left, -srcBounds.top);
- /* Draw it to the screen */
- DrawPicture( pict, &srcBounds );
-
- srcWorld = PictToGWorld( pict, &srcBounds );
- if(srcWorld == nil)
- return memFullErr;
-
- srcBounds = srcWorld->portRect;
- SetPt(&srcCenter, srcBounds.right + srcBounds.left >> 1,
- srcBounds.bottom + srcBounds.top >> 1);
- SetPt(&screenCenter, thePort->portRect.right - thePort->portRect.left >> 1,
- thePort->portRect.bottom - thePort->portRect.top >> 1);
-
- {
- mapping map;
- GWorldPtr dstWorld, maskWorld;
- Rect dstBounds, screenBounds, maskBounds;
- PixMapHandle dstPixels, maskPixels;
-
- SetIdentityMapping(&map);
- ScaleMapping(&map, ff(1) + 0x8000, ff(1) + 0x8000, ff(srcCenter.h), ff(srcCenter.v));
-
- dstWorld = MapGWorldTent(srcWorld, &map, &maskWorld);
- dstPixels = GetGWorldPixMap( dstWorld );
- maskPixels = GetGWorldPixMap( maskWorld );
- dstBounds = dstWorld->portRect;
- maskBounds = maskWorld->portRect;
-
- screenBounds = dstBounds;
- CenterRect(&screenBounds, screenCenter.h, screenCenter.v);
-
- LockPixels(dstPixels);
- LockPixels(maskPixels);
- CopyDeepMask((BitMap*)*dstPixels, (BitMap*)*maskPixels, &thePort->portBits,
- &dstBounds, &maskBounds, &screenBounds, srcCopy + ditherCopy, 0);
- DisposeGWorld( maskWorld );
- DisposeGWorld( dstWorld );
- }
- DisposeGWorld( srcWorld );
- return noErr;
- }
-
- OSErr TestRotate(PicHandle pict)
- {
- GWorldPtr srcWorld;
- Rect srcBounds;
- Point srcCenter, screenCenter;
- short err;
-
- srcBounds = (*pict)->picFrame;
- OffsetRect( &srcBounds, -srcBounds.left, -srcBounds.top);
- /* Draw it to the screen */
- DrawPicture( pict, &srcBounds );
-
- srcWorld = PictToGWorld( pict, &srcBounds );
- if(srcWorld == nil)
- return memFullErr;
-
- srcBounds = srcWorld->portRect;
- SetPt(&srcCenter, srcBounds.right + srcBounds.left >> 1,
- srcBounds.bottom + srcBounds.top >> 1);
- SetPt(&screenCenter, thePort->portRect.right - thePort->portRect.left >> 1,
- thePort->portRect.bottom - thePort->portRect.top >> 1);
-
- {
- mapping map;
- GWorldPtr dstWorld, maskWorld;
- Rect dstBounds, screenBounds, maskBounds;
- PixMapHandle dstPixels, maskPixels;
-
- SetIdentityMapping(&map);
- RotateMapping(&map, ff(35), ff(srcCenter.h), ff(srcCenter.v));
-
- dstWorld = MapGWorldBox(srcWorld, &map, &maskWorld);
- dstPixels = GetGWorldPixMap( dstWorld );
- maskPixels = GetGWorldPixMap( maskWorld );
- dstBounds = dstWorld->portRect;
- maskBounds = maskWorld->portRect;
-
- screenBounds = dstBounds;
- CenterRect(&screenBounds, screenCenter.h, screenCenter.v);
-
- LockPixels(dstPixels);
- LockPixels(maskPixels);
- CopyDeepMask((BitMap*)*dstPixels, (BitMap*)*maskPixels, &thePort->portBits,
- &dstBounds, &maskBounds, &screenBounds, srcCopy + ditherCopy, 0);
- DisposeGWorld( maskWorld );
- DisposeGWorld( dstWorld );
- }
- DisposeGWorld( srcWorld );
- return noErr;
- }
-
- OSErr TestWarp(PicHandle pict)
- {
- GWorldPtr srcWorld;
- Rect srcBounds;
- Point srcCenter, screenCenter;
- short err;
-
- srcBounds = (*pict)->picFrame;
- OffsetRect( &srcBounds, -srcBounds.left, -srcBounds.top);
- /* Draw it to the screen */
- DrawPicture( pict, &srcBounds );
-
- srcWorld = PictToGWorld( pict, &srcBounds );
- if(srcWorld == nil)
- return memFullErr;
-
- srcBounds = srcWorld->portRect;
- SetPt(&srcCenter, srcBounds.right + srcBounds.left >> 1,
- srcBounds.bottom + srcBounds.top >> 1);
- SetPt(&screenCenter, thePort->portRect.right - thePort->portRect.left >> 1,
- thePort->portRect.bottom - thePort->portRect.top >> 1);
-
- {
- mapping map;
- GWorldPtr dstWorld, maskWorld;
- Rect dstBounds, screenBounds, maskBounds;
- PixMapHandle dstPixels, maskPixels;
-
- SetIdentityMapping(&map);
-
- dstWorld = FancyMapGWorld(srcWorld, &map, &maskWorld);
- dstPixels = GetGWorldPixMap( dstWorld );
- maskPixels = GetGWorldPixMap( maskWorld );
- dstBounds = dstWorld->portRect;
- maskBounds = maskWorld->portRect;
-
- screenBounds = dstBounds;
- CenterRect(&screenBounds, screenCenter.h, screenCenter.v);
-
- LockPixels(dstPixels);
- LockPixels(maskPixels);
- CopyDeepMask((BitMap*)*dstPixels, (BitMap*)*maskPixels, &thePort->portBits,
- &dstBounds, &maskBounds, &screenBounds, srcCopy + ditherCopy, 0);
- DisposeGWorld( maskWorld );
- DisposeGWorld( dstWorld );
- }
- DisposeGWorld( srcWorld );
- return noErr;
- }
-
- OSErr TestRectangleEffect(PicHandle pict)
- {
- GDHandle oldGD;
- GWorldPtr oldGW;
- GWorldPtr myOffGWorld;
- GWorldPtr myOffGWorld1;
- PixMapHandle myPixMapHandle;
- PixMapHandle myPixMapHandle1;
- CTabHandle myGrayCTable;
- Rect bounds, mybounds, blastRect;
-
- bounds = (*pict)->picFrame;
- mybounds = bounds;
- OffsetRect( &mybounds, -mybounds.left, -mybounds.top);
- /* Draw it to the screen */
- DrawPicture( pict, &mybounds );
- OffsetRect( &bounds, 100, 100 );
-
- if( !NewGWorld( &myOffGWorld, 32, &bounds, 0, 0, 0 ) )
- {
- blastRect.left = 0;
- blastRect.top = 0;
- GetGWorld(&oldGW,&oldGD);
- myPixMapHandle = GetGWorldPixMap( myOffGWorld );
-
- SetGWorld(myOffGWorld,nil);
- LockPixels( myPixMapHandle );
- EraseRect( &bounds ); /* clear the GWorld */
-
- /* Draw it to the GWorld */
- DrawPicture( pict, &bounds );
- UnlockPixels( myPixMapHandle );
- SetGWorld(oldGW,oldGD);
-
- blastRect.right = 10;
- blastRect.bottom = 10;
- ImageBlastRect( &blastRect, myOffGWorld );
- CopyBits( (BitMap *)*myPixMapHandle, (BitMap *)&thePort->portBits,
- &bounds, &bounds, srcCopy + ditherCopy, 0 );
- DisposeGWorld( myOffGWorld );
- }
- else
- return memFullErr;
- return noErr;
- }
-